package com.itjavas.cslp2.mapper;

import com.itjavas.cslp2.pojo.entity.Course;
import com.itjavas.cslp2.pojo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    public User findCourseById(int CourseId);
    //签到积分+2
    @Update("update users set point=point+2 where id=#{userId}")
    Boolean point(Integer id);

    //登录，返回user是为了检查找到没有
    @Select("select * from users where name=#{name}")
    User login(String name);

    //注册
    @Insert("insert into users(name,password) values (#{name},#{password})")
    Boolean register(User user);

    //主页的查询用户信息,但是不查密码
    @Select("SELECT id, name,point,mail,status,nickname FROM users WHERE name = #{name}")
    User gerUserInfo(String name);
    //主页的编辑用户信息
    @Update("update users set name=#{name},password=#{password},nickname=nickname,mail=mail where id=#{id}")
    Boolean editUser(User user);

    //修改用户密码
    @Update("update users set password=#{password} where id=#{id}")
    Boolean editPassword(User user);
    //编辑账户使用状态
    @Update("update users set status=#{status} where id=#{id}")
    Boolean editStatue(User user);

    //根据用户获取选课信息
    @Select("select * from courses where id in (select course_id from record  where user_id = #{id});")
    List<Course> getRecordByUser(User user);

//    @Select("select * from users where name = #{name} and password = #{password}")
//    User getUserByNameAndPassword(@Param("name") String name, @Param("password") String password);
//
//    @Insert("INSERT INTO users (name, password) VALUES (#{name}, #{password})")
//    void insertUser(@Param("name") String name, @Param("password") String password);
}
